<!doctype html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/>
        <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
        <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
        <meta name="msapplication-TileColor" content="#206bc4"/>
        <meta name="theme-color" content="#206bc4"/>
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
        <meta name="apple-mobile-web-app-capable" content="yes"/>
        <meta name="mobile-web-app-capable" content="yes"/>
        <meta name="HandheldFriendly" content="True"/>
        <meta name="MobileOptimized" content="320"/>
        <meta name="robots" content="noindex,nofollow,noarchive"/>
        <link rel="icon" href="./favicon.ico" type="image/x-icon"/>
        <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon"/>
        <!-- CSS files -->
        <link href="https://cdn.bootcdn.net/ajax/libs/zTree.v3/3.5.01/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
        <link href="/dist/css/tabler.min.css" rel="stylesheet"/>
        <link href="/dist/css/demo.min.css" rel="stylesheet"/>
        <link href="/dist/css/metroStyle/metroStyle.css" rel="stylesheet"/>
        <style>
            body {
                display: none;
            }
        </style>
    </head>
    <body class="antialiased">
        <div class="page">
            <div class="content">
                <div class="container-xl">
                    <div class="row">
                        <div class="col-12">
                            <div class="row" style="padding: 20px">
                                <form>
                                    <div class="mb-3">
                                        <label class="form-label">上级菜单</label>
                                        <ul id="menuTree" class="ztree"></ul>
                                    </div>
                                    <div class="mb-3">
                                        <label class="form-label">名称</label>
                                        <input type="text" class="form-control menu_name" th:value="${menu.menuName}">
                                    </div>
                                    <div id="menu_url" class="mb-3">
                                        <label class="form-label">地址</label>
                                        <input type="text" class="form-control url" th:value="${menu.url}">
                                    </div>
                                    <div id="menu_per" class="mb-3">
                                        <label class="form-label">权限</label>
                                        <input type="text" class="form-control menu_permission"
                                               th:value="${menu.permission}">
                                    </div>
                                    <div class="form-group mb-3">
                                        <div class="form-label">状态</div>
                                        <div class="form-check-inline">
                                            <label class="form-check form-check-inline">
                                                <input class="form-check-input" type="radio" name="menuStatus"
                                                       value="false" th:checked="${menu.isDelete == false}"/>
                                                <span class="form-check-label">有效</span>
                                            </label>
                                            <label class="form-check form-check-inline">
                                                <input class="form-check-input" type="radio" name="menuStatus"
                                                       value="true" th:checked="${menu.isDelete == true}"/>
                                                <span class="form-check-label">失效</span>
                                            </label>
                                        </div>
                                    </div>

                                    <div class="mb-3">
                                        <label class="form-label">排序</label>
                                        <input type="number" min="0" class="form-control menu_sort"
                                               th:value="${menu.sort}">
                                    </div>
                                    <div class="form-footer">
                                        <button type="button" class="btn btn-primary formCommit">提交</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Libs JS -->
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.7/jquery.min.js"></script>
        <script src="/dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="https://cdn.bootcdn.net/ajax/libs/zTree.v3/3.5.01/js/jquery.ztree.all.js"></script>
        <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js"></script>
        <script src="/dist/js/menu.js"></script>
        <!-- Tabler Core -->
        <script src="/dist/js/tabler.min.js"></script>
        <script src="/dist/js/menu/menuUpdate.js"></script>
        <script type="text/javascript">
            var menuId = '[[${menu.id}]]';
            var menuPid = '[[${pid}]]';
            var menuType = '[[${type}]]';
            if ('D' == menuType) {
                $("#menu_url").hide();
                $("#menu_per").hide();
            }
            if ('B' == menuType) {
                $("#menu_url").hide();
            }
            var setting = {
                check: {
                    enable: true,
                    chkStyle: "radio",
                    radioType: "all"
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                }
            };

            var ztree;
            $(document).ready(function () {
                var treeData = null;
                $.ajax({
                    type: "POST",
                    url: '/menu/getZtreeMenu',
                    data: JSON.stringify(["D", "M"]),
                    async: false,
                    dataType: 'json',
                    contentType: 'application/json',
                    success: function (res) {
                        treeData = res;
                    }
                });
                ztree = $.fn.zTree.init($("#menuTree"), setting, treeData);
                ztree.expandAll(true);
                var nodes = ztree.transformToArray(ztree.getNodes());
                if (nodes.length > 0) {
                    for (var i = 0; i < nodes.length; i++) {
                        if (menuPid == nodes[i].id) {
                            nodes[i].checked = true;
                            ztree.updateNode(nodes[i]);
                            return;
                        }
                    }
                }
            });
        </script>
    </body>
</html>
